
#include <Inklude/ikCString.h>

//using namespace std;
using namespace Inklude;

ikCString::ikCString(std::string& _String)
{
    m_string.assign(_String.begin(), _String.end());
    m_wstring.assign(_String.begin(), _String.end());
}

ikCString::ikCString(std::wstring& _String)
{
    m_string.assign(_String.begin(), _String.end());
    m_wstring.assign(_String.begin(), _String.end());
}

ikCString::ikCString(const char* _String)
{
    m_string.assign(_String);
    wchar_t* _str = CharToWChar(_String);
    m_wstring.assign(_str);
    delete _str;
}

ikCString::ikCString(const wchar_t* _String)
{
    m_wstring.assign(_String);
    char* _str = WCharToChar(_String);
    m_string.assign(_str);
    delete _str;
}

ikCString::~ikCString()
{

}

#ifndef UNICODE
    const char* ikCString::c_tstr()
    {
        return ikCString::c_str();
    }
#else
    const wchar_t* ikCString::c_tstr()
    {
        return ikCString::c_wstr();
    }
#endif

const char* ikCString::c_str()
{
    return m_string.c_str();
}

const wchar_t* ikCString::c_wstr()
{
    return m_wstring.c_str();
}

std::string& ikCString::ToString()
{
    return m_string;
}

std::wstring& ikCString::ToWString()
{
    return m_wstring;
}

bool ikCString::operator== (Inklude::ikCString& _String)
{
    return (0 == strcmp(_String.c_str(), m_string.c_str()));
}

bool ikCString::operator== (std::string& _String)
{
    return (0 == strcmp(_String.c_str(), m_string.c_str()));
}

bool ikCString::operator== (std::wstring& _String)
{
    char* str = WCharToChar(_String.c_str());
    bool result = (0 == strcmp(str, m_string.c_str()));
    delete str;
    return result;
}

bool ikCString::operator== (char* _String)
{
    return (0 == strcmp(_String, m_string.c_str()));
}

bool ikCString::operator== (wchar_t* _String)
{
    char* str = WCharToChar(_String);
    bool result = (0 == strcmp(str, m_string.c_str()));
    delete str;
    return result;
}

void ikCString::operator= (const Inklude::ikCString _String)
{
    m_string.clear();
    m_string.assign(_String.m_string);
    m_wstring.clear();
    m_wstring.assign(_String.m_wstring);
}

void ikCString::operator= (const std::string& _String)
{
    Clear();
    m_string.assign(_String);
    wchar_t* str = CharToWChar(_String.c_str());
    m_wstring.assign(str);
    delete str;
}

void ikCString::operator= (const std::wstring& _String)
{
    Clear();
    m_wstring.assign(_String);
    char* str = WCharToChar(_String.c_str());
    m_string.assign(str);
    delete str;
}

void ikCString::operator= (const char* _String)
{
    Clear();
    m_string.assign(_String);
    wchar_t* str = CharToWChar(_String);
    m_wstring.assign(str);
    delete str;
}

void ikCString::operator= (const wchar_t* _String)
{
    Clear();
    m_wstring.assign(_String);
    char* str = WCharToChar(_String);
    m_string.assign(str);
    delete str;
}

void ikCString::Assign(const Inklude::ikCString _String)
{
    *this = (_String);
}

void ikCString::Assign(const std::string& _String)
{
    *this = (_String);
}

void ikCString::Assign(const std::wstring& _String)
{
    *this = (_String);
}

void ikCString::Assign(const char* _String)
{
    *this = (_String);
}

void ikCString::Assign(const wchar_t* _String)
{
    *this = (_String);
}

void ikCString::Assign(const int value)
{
    *this = (value);
}

void ikCString::Assign(const float value)
{
    *this = (value);
}

ikCString ikCString::operator+ (Inklude::ikCString _String)
{
    m_string += _String.c_str();
    wchar_t* _str = CharToWChar(m_string.c_str());
    m_wstring.assign(_str);
    delete _str;
    return *this;
}

ikCString ikCString::operator+ (std::string& _String)
{
    m_string += _String.c_str();
    wchar_t* _str = CharToWChar(m_string.c_str());
    m_wstring.assign(_str);
    delete _str;
    return *this;
}

ikCString ikCString::operator+ (std::wstring& _String)
{
    m_wstring += _String.c_str();
    char* _str = WCharToChar(m_wstring.c_str());
    m_string.assign(_str);
    delete _str;
    return *this;
}

ikCString ikCString::operator+ (char* _String)
{
    m_string += _String;
    wchar_t* _str = CharToWChar(m_string.c_str());
    m_wstring.assign(_str);
    delete _str;
    return *this;
}

ikCString ikCString::operator+ (wchar_t* _String)
{
    m_wstring += _String;
    char* str = WCharToChar(m_wstring.c_str());
    m_string.assign(str);
    delete str;
    return *this;
}


void ikCString::operator= (int value)
{
    m_string.clear();
    m_wstring.clear();
    char buf[100];
    sprintf_s(buf, "%d", value);
    m_string.assign(buf);
    wchar_t* _str = CharToWChar(m_string.c_str());
    m_wstring.assign(_str);
    delete _str;
}

void ikCString::operator= (float value)
{
    m_string.clear();
    m_wstring.clear();
    char buf[100];
    sprintf_s(buf, "%f", value);
    m_string.assign(buf);
    wchar_t* _str = CharToWChar(m_string.c_str());
    m_wstring.assign(_str);
    delete _str;
}

void ikCString::Clear()
{
    m_string.clear();
    m_wstring.clear();
}

unsigned int ikCString::Length()
{
    return m_string.length();
}

wchar_t* ikCString::CharToWChar(const char* _String)
{
    size_t _len = strlen(_String);
    _len++;
    wchar_t* _str = new wchar_t[_len];
    mbstowcs_s(&_len, _str, _len, _String, _len);
    return _str;
}

char* ikCString::WCharToChar(const wchar_t* _String)
{
    size_t _len = wcslen(_String);
    _len++;
    char* _str = new char[_len];
    wcstombs_s(&_len, _str, _len, _String, _len);
    return _str;
}

int ikCString::ToInt()
{
    return atoi(m_string.c_str());
}

float ikCString::ToFloat()
{
    return (float)(atof(m_string.c_str()));
}



//static wchar_t* Inverse(const wchar_t* _String, int _StringSize)
//{
//    size_t _len = wcslen(_String);
//    size_t _bound = _len;
//    wchar_t* _str = new wchar_t[_len];
//
//    for (int i=0; i<_bound; i++)
//    {
//        _str[i] = _String[_len];
//        _len--;
//    }
//}
//
//static char* Inverse(const char* _String, int _StringSize)
//{
//}
//
